package com.icare.trade.server.rest;

import com.alibaba.fastjson.JSON;
import com.icare.common.service.utils.IdWorkerUtil;
import com.icare.shop.common.base.ResponseResult;
import com.icare.trade.server.req.SubmitOrderReq;
import com.icare.trade.server.resp.SubmitOrderResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <pre>
 *    author  : tianhaibo
 *    email   : tianhaibo@jshuii.com
 *    time    : 2020/3/12   20:04
 *    desc    :
 *    version : v1.0
 * </pre>
 */
@Slf4j
@RestController
@RequestMapping("v1")
@Api(tags = "订单",value = "订单")
public class OrderRest {

    @GetMapping("submitOrder")
    @ApiOperation("提交订单")
    ResponseResult<SubmitOrderResp> submitOrder(@RequestBody SubmitOrderReq req){
        log.info("提交订单，data={}", JSON.toJSONString(req));
        SubmitOrderResp orderResp = SubmitOrderResp.builder()
                .orderId(IdWorkerUtil.nextId())
                .orderNo("PO" + IdWorkerUtil.nextId())
                .orderTime(new Date())
                .productId(req.getProductId())
                .userId(req.getUserId())
                .status(0)
                .build();
        return ResponseResult.success(orderResp);
    }
}
